const mongoose = require('mongoose');
const db = require('./db');

var goodSchema = new mongoose.Schema({
	author:String,
	title:String,
	price:Number,
    content:String,
    tag:String,
    time:Object,
    shopImg:String,
    monNum:Number,
    address:String,
    manjian:String,
    comments:[{
    	content:String,
    	buyer:String,
    	time:Object
    }]
})
goodSchema.methods.timeFabu = function(){
	var now = new Date();
    var times = {
        date:now,
        year:now.getFullYear(),
        month:now.getFullYear() + '-' + (now.getMonth() + 1 ),
        day:now.getFullYear() + '-' + (now.getMonth() + 1 ) + '-' + now.getDate(),
        minute:now.getFullYear() + '-' + (now.getMonth() + 1 ) + '-' + now.getDate() +
                ' ' + ( now.getHours() < 10 ? '0':'' ) + now.getHours() +
                ':' + ( now.getMinutes() < 10 ? '0' : '' ) + now.getMinutes()
    }
    return times;
}
const GoodModel = mongoose.model('goods', goodSchema);
module.exports =GoodModel;